package zhoug.zui.menu;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.WindowManager;

import java.util.List;

import androidx.annotation.NonNull;
import zhoug.common.anim.ZAnimations;
import zhoug.logging.Logger;
import zhoug.zui.R;
import zhoug.zui.dialog.ZUIBaseDialog;

/**
 * 多级菜单
 */
public class ZUIMultiMenuDialog extends ZUIBaseDialog {
    private static final String TAG = ">>>ZUIMenuDialog";
    private static final boolean DEBUG = false;
    private ZUIMultiMenuView mMenuView;
    private List<? extends Menu> menus;
    private int selectColor = Color.parseColor("#22adff");
    private ZUIMultiMenuView.Callback mCallback;

    public ZUIMultiMenuDialog(@NonNull Context context) {
        this(context, 0);
    }


    public ZUIMultiMenuDialog(@NonNull Context context, int themeResId) {
        this(context, themeResId, 0, 0);
    }

    public ZUIMultiMenuDialog(@NonNull Context context, int themeResId, int defStyleAttr, int defStyleRes) {
        super(context, themeResId, defStyleAttr, defStyleRes);
    }

    @Override
    protected void initialize(@NonNull Context context, int defStyleAttr, int defStyleRes) {
        super.initialize(context, defStyleAttr, defStyleRes);
        setWindowAnimations(ZAnimations.ANIM_DOWN);
        setAttributes(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM);
        setFullWidth(true);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.zui_multi_menu_dialog;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        setCanceledOnTouchOutside(true);
        mMenuView = findViewById(R.id.menuView);
        mMenuView.setCallback(mCallback);
        mMenuView.setSelectColor(selectColor);
        mMenuView.setMenus(menus);
        if (DEBUG) {
            Logger.d(TAG, "init:menus=" + menus);
        }
    }

    public void setSelectColor(int selectColor) {
        this.selectColor = selectColor;
    }

    public List<? extends Menu> getMenus() {
        return menus;
    }


    public void setMenus(List<? extends Menu> menus) {
        this.menus = menus;
        if (mMenuView != null) {
            mMenuView.setMenus(menus);
        }
    }

    public void notifyDataSetChanged() {
        if (mMenuView != null) {
            mMenuView.notifyDataSetChanged();
        }
    }

    public ZUIMultiMenuView.Callback getCallback() {
        return mCallback;
    }

    public void setCallback(ZUIMultiMenuView.Callback callback) {
        this.mCallback = callback;
    }


}
